<?php
/* 
    Project     : 48c6c450f1a4a0cc53d9585dc0fee742
    Created on  : Mar 16, 2013, 11:29:15 PM
    Author      : Truong Khuong - khuongxuantruong@gmail.com
    Description :
        Purpose of the stylesheet follows.
*/
class news_model extends backend_Model {

    function __construct()
    {
        parent::__construct('news','');
    }
    function binding($cates=null){
        $where = "WHERE  true";
        if($cates!=null){
            $where='WHERE (';
            $cates=  explode('-', $cates);
            foreach ($cates as $c){
                if(!empty($c)){
                    $where.="`CategoryId` like '%$c%' OR ";
                }
            }
            $where.=" FALSE)";
        }
            $this->datatables_config=array(
                    "table"=>"news",
                    "select"=>"
                        SELECT SQL_CALC_FOUND_ROWS
                            news.Id,
                            news.Title,
                            news.Alias,
                            news.Thumb,
                            news.`Desc`,
                            news.CategoryId,
                            news.Position,
                            news.Tag,
                            news.Hot,
                            news.StartDate,
                            news.`Insert`,
                            news.`Update`,
                            news.`Delete`,
                            news.Related,
                            news.Active,
                            news.EndDate,
                            news.Link
                        FROM news",
                    "where"     =>$where,
                    "order_by"=>"Order By `Insert` DESC  ",
                    "columnmaps"=>array(
                            
                    )
            );
            return $this->_bindingdata();
    }
    function search($q=''){
        $query = $this->db
                ->select('Id as id,Title')
                ->like('Title',$q)
                ->from($this->table)
                ->order_by('Insert', 'DESC')
                ->limit(10)
                ->get();
        return $query->result();
    }
    function getIn($ids=  array()){
        $query = $this->db
                ->select('Id as id,Title')
                ->where_in('Id',$ids)
                ->from($this->table)
                ->order_by('Insert', 'DESC')
                ->get();
        return $query->result();
    }
}
?>
